package com.aaa.service.impl;

import com.aaa.entity.User;
import com.aaa.mapper.UserMapper;
import com.aaa.service.UserService;
import com.aaa.util.WebUtil;
import com.aaa.vo.Result;
import com.aaa.vo.UserVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: qy158-system
 * @description:
 * @author: 闫克起2
 * @create: 2022-10-10 10:34
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Result findByNameAndPass(String name, String password) {
        User user = userMapper.selectByNameAndPass(name, password);
        if(user!=null){
            //登录成功后保存用户信息再session中
            WebUtil.getSession().setAttribute("user",user);
            return new Result(2000,"登录成功");
        }else{
            return new Result(5000,"登录失败");
        }
    }

    @Override
    public Result findByCondition(Integer currentPage, Integer pageSize, UserVo userVo) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> users = userMapper.selectAll(userVo.getUsername(), userVo.getRealname());

        PageInfo<User> pageInfo=new PageInfo<>(users);

        return new Result(2000,"查询成功",pageInfo);
    }
}
